﻿namespace PhoneUtils.View
{
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;

    /// <summary>
    /// This datatemplate selector selects the template from the application resources using the name of the item type with the Template suffix as key.
    /// </summary>
    public class TypeDataTemplateSelector : DataTemplateSelector
    {
        /// <summary>
        /// Provides implementation to select the appropriate template for the given item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="container">The container.</param>
        /// <returns>
        /// The selected template.
        /// </returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            return (DataTemplate)Application.Current.Resources[item.GetType().Name + "Template"];
        }
    }
}
